package uk.co.droidinactu.inlibrislibertas.model;

import java.util.ArrayList;
import java.util.HashMap;

import uk.co.droidinactu.common.model.AbstractDataObj;
import android.content.ContentValues;
import android.provider.BaseColumns;

public class RecentEBook extends AbstractDataObj {

    /**
     * this number denotes the version of this class. so that we can decide if
     * the structure of this class is the same as the one being deserialized
     * into it
     */
    private static final long serialVersionUID = 1L;

    public static final String DATABASE_TABLE_NAME = "recentEbooks";
    public static final String FIELD_NAME_EBOOK_ID = "ebookId";

    public Long ebookId;

    public RecentEBook() {
    }

    public RecentEBook(final HashMap<String, String> aRow) {
        super(aRow);
        try {
            ebookId = Long.parseLong(aRow.get(RecentEBook.FIELD_NAME_EBOOK_ID));
        } catch (final Exception e) {
            ;
        }
    }

    @Override
    public ContentValues getContentValues() {
        final ContentValues map = super.getContentValues();
        map.put(RecentEBook.FIELD_NAME_EBOOK_ID, ebookId);
        return map;
    }

    @Override
    public HashMap<Integer, ArrayList<String>> getFields() {
        final HashMap<Integer, ArrayList<String>> fields = super.getFields();

        int x = fields.size();
        fields.put(x++, getArrayList(RecentEBook.FIELD_NAME_EBOOK_ID, "INTEGER"));
        return fields;
    }

    @Override
    public String getSelectAllSql() {
        final String ebkTblName = new EBook().getTableName();

        final String tmpStr = "SELECT * FROM " + getTableName() + " JOIN " + ebkTblName + " ON " + getTableName() + "."
                + FIELD_NAME_EBOOK_ID + " = " + ebkTblName + "." + BaseColumns._ID + " order by "
                + AbstractDataObj.FIELD_NAME_LAST_UPDATED + " DESC";
        return tmpStr;
    }

    public String getSqlUpdateFromV001() {
        // TODO Auto-generated method stub
        return null;
    }

    public String getSqlUpdateFromV002() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getTableName() {
        return RecentEBook.DATABASE_TABLE_NAME;
    }

}
